package IO.io;

import org.junit.Test;

import java.io.*;

public class BufferTest {
    @Test
    public void test(){
        BufferedInputStream bis=null;
        BufferedOutputStream bos=null;
        try {
            File srcFile = new File("爱情与友情.jpg");
            File destFile = new File("爱情与友情3.jpg");
            FileInputStream fis = new FileInputStream(srcFile);
            FileOutputStream fos = new FileOutputStream(destFile);
            bis=new BufferedInputStream(fis);
            bos=new BufferedOutputStream(fos);
            byte[] bytes=new byte[10];
            int len;
            while ((len=bis.read(bytes))!=-1){
                bos.write(bytes,0,len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(bos!=null){
                try {
                    bos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(bis!=null){
                try {
                    bis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
